<template>
	<view>
		<view class="dbCard" @click="skipDbPageFun('sysmsg')">
			<view>
				<image src="@/static/crm/thread.png" mode="aspectFill"></image>
				<text>我的消息</text>
			</view>
			<view>
				<text class="dbNum" :class="sysMsgNum > 0 ? 'redColor': ''">{{sysMsgNum}}</text>
				<u-icon color="#888888" name="arrow-right"></u-icon>
			</view>
		</view>
		
		<view class="dbCard" @click="skipDbPageFun('oanotifyuser')">
			<view>
				<image src="@/static/crm/thread.png" mode="aspectFill"></image>
				<text>系统公告</text>
			</view>
			<view>
				<text class="dbNum" :class="oaNotifyNum > 0 ? 'redColor': ''">{{oaNotifyNum}}</text>
				<u-icon color="#888888" name="arrow-right"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	let that = '';
	import {apiSysMsg,apiSysNotifyUser} from '@/api/admin.js'
	import {getDayFun, getDayByNumFun} from '@/utils/date.js'
	export default {
		data() {
			return {
				menuList: [],
				sysMsgNum:0,
				oaNotifyNum:0,
			}
		},
		onLoad() {
			that = this;
			that.getSysMsgFun();
			that.getSysNotifyFun();
		},
		onShow() {
			if(uni.$isLoginFun()) {
				that.getSysMsgFun();
				that.getSysNotifyFun();
			}
		},
		methods: {
			getSysMsgFun: function() {
				let user = uni.$userInfo || null;
				let reqData = {
					action: 'get_list',
					params: {
						matchObj:{
							sys_user_id: uni.$userInfo.id,
							deal_user_id: uni.$userInfo.id,
							deal_status:0
						},
						sortObj:{}
					}
				}
				uni.showLoading({
					title: '刷新中...',
					mask: true
				})
				apiSysMsg(reqData)
					.then(res => {
						let data = res.data;
						that.sysMsgNum=data.total;
						 that.setTabBarNums()
						setTimeout(() => {
							//延时关闭  加载中的 loading框
							uni.hideLoading()
						}, 188);
					})
			},
			getSysNotifyFun: function() {
				let user = uni.$userInfo || null;
				let reqData = {
					action: 'get_list',
					params: {
						matchObj:{
							owner_user_id: uni.$userInfo.id,
							read_state:0,
						},
						sortObj:{}
					}
				}
				uni.showLoading({
					title: '刷新中...',
					mask: true
				})
				apiSysNotifyUser(reqData)
					.then(res => {
						let data = res.data;
						that.oaNotifyNum=data.total;
						 that.setTabBarNums()
						setTimeout(() => {
							//延时关闭  加载中的 loading框
							uni.hideLoading()
						}, 188);
					})
			},
			setTabBarNums:function(){
				let total=that.sysMsgNum+that.oaNotifyNum
				if(total > 0) {
					if(total > 99) {
						total = '99+'
					}
					uni.setTabBarBadge({
						index: 0,
						text: total + ''
					})
				} else {
					uni.hideTabBarRedDot({
						index: 0
					})
				}
			},
			skipDbPageFun: function(gotopage) {
				let url=''
				if(gotopage=='sysmsg'){
					url='./sys_msg/show';
				}else if(gotopage=='oanotifyuser'){
					url='./sys_notify_user/show';
				}
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style>
	.dbCard {
		width: 686rpx;
		margin: 26rpx 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 26rpx 16rpx;
		border: 1rpx solid #DDDDDD;
		border-radius: 26rpx;
	}
	.dbCard:active {
		background-color: #DDDDDD;
	}
	.dbCard image {
		width: 50rpx;
		height: 50rpx;
	}
	.dbCard>view {
		display: flex;
		align-items: center;
	}
	.dbCard>view>text {
		margin: 0 16rpx;
	}
	.dbNum {
		font-size: 16px;
		color: #007AFF;
	}
</style>
